﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Code.Models;

namespace QianBuo.Lottery.Web.Models
{
    [ModelBinder(typeof(NameValueModelBinder))]
    [Serializable]
    public class ModelNameValue<N, V> : NameValue<N, V>
    {
        public ModelNameValue() { }
        public ModelNameValue(NameValue<N, V> items)
        {
            this.AddRange(items);
        }
        public ModelNameValue(IEnumerable<NameValueItem<N, V>> items)
        {
            this.AddRange(items);
        }

        
    }


    public class NameValueModelBinder : IModelBinder
    {

        #region IModelBinder 成员

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            object obj = null;
            System.IO.MemoryStream sm = null;

            try
            {

                var sl = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                string str = controllerContext.HttpContext.Request.Form[bindingContext.ModelName];

                var bytes = Convert.FromBase64String(str);

                sm = new System.IO.MemoryStream(bytes);

                obj = sl.Deserialize(sm);

            }
            catch
            {

            }
            finally
            {
                if (sm != null)
                    sm.Dispose();
            }

            return obj;
        }

        #endregion
    }

    public class UserModel
    {
        public Guid UserID { get; set; }
        public string LoginName { get; set; }
        public string Commands { get; set; }
        public UserState State { get; set; }
        public double Balance { get; set; }
        public double FreezeMoney { get; set; }
        public decimal Ratio { get; set; }
        public int WinModelID { get; set; }
        public string Email { get; set; }
        public UserType UserType { get; set; }
        public string LoginIP { get; set; }
        public string SessionID { get; set; }
        public string Them { get; set; }
        public bool IsLoad { get; set; }
        public DateTime AddTime { get; set; }
    }

    public class AdminModel
    {
        public Guid AdminID { get; set; }
        public string LoginName { get; set; }
        public AdminState State { get; set; }
        public int RoleID { get; set; }
        public string LoginIP { get; set; }
        public string SessionID { get; set; }
        public bool IsLoad { get; set; }
        public DateTime AddTime { get; set; }
    }
}